﻿using System.Web.Mvc;
using System.Web.Routing;
using Morus;
using Morus.Infrastructure;

namespace KAKA.Infrastructure
{
    public class RegisterRoutes : IBootstrapperTask
    {
        private readonly RouteCollection _routes;

        public RegisterRoutes(RouteCollection routes)
        {
            Check.Argument.IsNotNull(routes, "routes");

            _routes = routes;
        }

        public RegisterRoutes()
            : this(RouteTable.Routes)
        {
        }

        public void Execute()
        {
            AreaRegistration.RegisterAllAreas();

            _routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            _routes.IgnoreRoute("{resource}.css");
            _routes.IgnoreRoute("{resource}.js");

            _routes.MapRoute(
                "Home",
                "{action}",
                new { controller = "Home", action = "Index" },
                new { action = "^(Index|About|Login|SignUp|Logout|Basic|ResetPassword|ResetPasswordSuccess|ChangePassword|ChangePasswordSuccess)$" });

            // see MobileVerificationAttribute
            _routes.MapRoute(
                "VerifyMobile",
                "Personal/VerifyMobile",
                new { controller = "Personal", action = "VerifyMobile" });

            // see EmailVerificationAttribute
            _routes.MapRoute(
                "VerifyEmail",
                "Personal/VerifyEmail",
                new { controller = "Personal", action = "VerifyEmail" });

            _routes.MapRoute(
                "ActivateEmail",
                "Personal/ActivateEmail/{token}",
                new { controller = "Personal", action = "ActivateEmail" });

            _routes.MapRoute(
                "Personal",
                "Personal/{action}",
                new { controller = "Personal", action = "Basic" });

            _routes.MapRoute(
                "Default",
                "{controller}/{action}/{id}",
                new { controller = "Home", action = "Index", id = UrlParameter.Optional });

            //RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
        }
    }
}